package com.mobisys.live.controller.statisticcontroller;

import com.mobisys.live.dao.model.UserVideoWatchingRecord;
import com.mobisys.live.response.Response;
import com.mobisys.live.service.UserVideoWatchingRecordService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import static com.mobisys.live.config.ResponseCode.*;

/*
* liu
* */
@RestController
public class VideoRecordController {
    @Autowired
    private UserVideoWatchingRecordService userVideoWatchingRecordService;
    private Logger logger = LogManager.getLogger(VideoRecordController.class.getName());

    /*
    * 获取点播观看人数相关数据
    * 匿名用户 anonymous_users
    * */
    @RequestMapping(value = "/video/record",method = RequestMethod.POST)
    public Response getVideoRecord(@RequestBody UserVideoWatchingRecord userVideoWatchingRecord){
        Response response = new Response();
        if(userVideoWatchingRecord == null){
            logger.debug("userVideoWatchingRecord获取失败");
            response.setRetureValue(RERCORD_VIDEO_ERROR);
            response.setRetureMsg(MSG_RERCORD_VIDEO_ERROR);
            return response;
        }
        int key = userVideoWatchingRecordService.insert(userVideoWatchingRecord);
        if(key <= 0){
            logger.debug("userVideoWatchingRecord插入失败");
            response.setRetureValue(RERCORD_VIDEO_ERROR);
            response.setRetureMsg(MSG_RERCORD_VIDEO_ERROR);
            return response;
        }
        response.setRetureValue(SUCCESS);
        response.setRetureMsg(MSG_SUCCESS);
        return response;

    }
}
